<%= error_messages_for 'query' %>

<div class="box">
<div class="tabular">
<%= hidden_field_tag 'gantt', '1' if params[:gantt] %>

<p><label for="query_name"><%=l(:field_name)%></label>
<%= text_field 'query', 'name', :size => 80 %></p>

<% if User.current.admin? || User.current.allowed_to?(:manage_public_queries, @project) %>
<p><label><%=l(:field_visible)%></label>
  <label class="block"><%= radio_button 'query', 'visibility', Query::VISIBILITY_PRIVATE %> <%= l(:label_visibility_private) %></label>
  <label class="block"><%= radio_button 'query', 'visibility', Query::VISIBILITY_ROLES %> <%= l(:label_visibility_roles) %>:</label>
  <% Role.givable.sorted.each do |role| %>
    <label class="block role-visibility"><%= check_box_tag 'query[role_ids][]', role.id, @query.roles.include?(role), :id => nil %> <%= role.name %></label>
  <% end %>
  <label class="block"><%= radio_button 'query', 'visibility', Query::VISIBILITY_PUBLIC %> <%= l(:label_visibility_public) %></label>
  <%= hidden_field_tag 'query[role_ids][]', '' %>
</p>
<% end %>

<p><label for="query_is_for_all"><%=l(:field_is_for_all)%></label>
<%= check_box_tag 'query_is_for_all', 1, @query.project.nil?,
      :disabled => (!@query.new_record? && (@query.project.nil? || (@query.is_public? && !User.current.admin?))) %></p>

<fieldset><legend><%= l(:label_options) %></legend>

<p><label for="query_horizontal_field"><%=l(:label_horizontal_field)%></label>
<%= select_tag 'query[horizontal_field]', report_column_options_for_select(@query,'horizontal_field'),:id =>"query_horizontal_field" %></p>
<p><label for="query_vertical_field"><%=l(:label_vertical_field)%></label>
<%= select_tag 'query[vertical_field]', report_column_options_for_select(@query,'vertical_field'),    :id =>"query_vertical_field"  %></p>

</fieldset>
</div>

<fieldset id="filters"><legend><%= l(:label_filter_plural) %></legend>
<%= render :partial => 'queries/filters', :locals => {:query => query}%>
</fieldset>





</div>

<%= javascript_tag do %>
$(document).ready(function(){
  $("input[name='query[visibility]']").change(function(){
    var checked = $('#query_visibility_1').is(':checked');
    $("input[name='query[role_ids][]'][type=checkbox]").attr('disabled', !checked);
  }).trigger('change');
});
<% end %>
